﻿#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void merge(int arr[], int L, int mid, int R, int sz)
{
	vector<int>v;
	v.assign(sz, 0);
	for (int i = 0; i < sz; i++)
	{
		v[i] = arr[i];
	}
	int current = L;
	int left = L;
	int right = mid + 1;
	while (left <= mid && right <= R)
	{
		if (v[left] <= v[right])
		{
			arr[current++] = v[left++];
		}
		else
		{
			arr[current++] = v[right++];
		}
	}
	while (left <= mid)
	{
		arr[current++] = v[left++];
	}
}
void mergeSort(int arr[], int L, int R, int sz)
{
	if (L < R) {
		int mid = L + ((R - L) >> 1);
		mergeSort(arr, L, mid, sz);
		mergeSort(arr, mid + 1, R, sz);
		merge(arr, L, mid, R, sz);
	}
}
int main()
{
	int arr[] = { 19 ,40 ,97 ,62 ,67 ,65, 5 ,88 ,36 ,77 ,32 ,46 ,93 ,85 ,2 ,99 ,94 ,61 ,98 ,75 ,74 ,25 ,80 ,49 ,17 ,16 ,90 ,70 ,72 ,30 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	mergeSort(arr, 0, sz - 1, sz);
	for (int i = 0; i < sz; i++)
	{
		cout << arr[i] << "  ";
	}
	cout << endl;
	system("pause");
	return 0;
}